package com.tjvib.bean;

import com.tjvib.sensor.LocalSensorData;
import com.tjvib.sensor.LpmsB2SensorData;
import com.tjvib.sensor.SensorData;
import com.tjvib.util.LogUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Arrays;
import java.util.List;

public class DataSet<T extends SensorData> {

    private DataSetInfo info;

    private List<T> content;

    public DataSet(DataSetInfo info, List<T> content) {
        this.info = info;
        this.content = content;
    }

    public DataSetInfo getInfo() {
        return info;
    }

    public void setInfo(DataSetInfo info) {
        this.info = info;
    }

    public List<T> getContent() {
        return content;
    }

    public void setContent(List<T> content) {
        this.content = content;
    }

    public String toJsonString() throws JSONException {
        JSONObject result = info.toJsonObject();

        JSONArray contentArray = new JSONArray();
        for (T t : content) {
            contentArray.put(t.toJsonObject());
        }
        result.put("content", contentArray.toString());
        return result.toString();
    }
}
